/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package classesInterface;

import classesBancodeDados.FichaObservacaoPA;
import classesBancodeDados.Paciente;
import classesBancodeDados.Responsavel;
import classesJpa.FichaObservacaoPAJpaController;
import classesJpa.ResponsavelJpaController;
import classesJpa.exceptions.NonexistentEntityException;
import classesMiolo.Formatador;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author Emerson
 */
public class TelaFichaObsPtAtd extends javax.swing.JFrame {

    /**
     * Creates new form Ficha_Obs_Pt_Atd
     */
    
    private static TelaFichaObsPtAtd uniqueInstance = null;
    
    private TelaFichaObsPtAtd() {
        initComponents();
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }

    public FichaObservacaoPA getFicha() {
        return ficha;
    }

    public void setFicha(FichaObservacaoPA ficha) {
        this.ficha = ficha;
    }
    
    public void turnEditable(boolean editable){
        botaoSalvar.setEnabled(editable);
        dataEntrada.setEditable(editable);
        dataAlta.setEditable(editable);
        cidDiagnostico.setEditable(editable);
        qDiarias.setEditable(editable);
        procedimento.setEditable(editable);
        observacao.setEditable(editable);
        nProntuario.setEditable(false);
        nomePaciente.setEditable(false);
        logradouro.setEditable(false);
        municipio.setEditable(false);
        cep.setEditable(false);
        telefone.setEditable(false);
        dataNascimento.setEditable(false);
        idade.setEditable(false);
        nomeMae.setEditable(false);
        nomeResp.setEditable(false);
        telResp.setEditable(false);
    }
    
    public void preencheCampos(Paciente paciente, FichaObservacaoPA observacaoPA){
        nProntuario.setText(observacaoPA.getNumeroProntuario());
        dataEntrada.setText(observacaoPA.getDataEntrada());
        nomePaciente.setText(paciente.getNome());
        logradouro.setText(paciente.getEndLogradouro() + ", " + paciente.getEndNumero() + ", " + paciente.getEndBairro());
        municipio.setText(paciente.getCidade());
        cep.setText(paciente.getCep());
        telefone.setText(paciente.getTelefone());
        dataNascimento.setText(paciente.getDataDeNascimento());
        idade.setText(paciente.getDataDeNascimento());
        nomeMae.setText(paciente.getNomeMae());
        ResponsavelJpaController rJpa = new ResponsavelJpaController();
        Responsavel resp = rJpa.findResponsavel(paciente.getCpfResp());
        if(resp == null){
            nomeResp.setText(paciente.getNomePai());
            telResp.setText("");
        } else {
            nomeResp.setText(resp.getNome());
            telResp.setText(resp.getTelefone());
        }
        dataAlta.setText(observacaoPA.getDataAlta());
        cidDiagnostico.setText(observacaoPA.getCidDiag());
        qDiarias.setText("" + observacaoPA.getQtdDiarias());
        procedimento.setText(observacaoPA.getProcedimento());
        observacao.setText(observacaoPA.getObs());
    }
    
    public static TelaFichaObsPtAtd getInstance(){
        if(uniqueInstance == null){
            uniqueInstance = new TelaFichaObsPtAtd();
        }
        return uniqueInstance;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        nProntuario = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        dataEntrada = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        nomePaciente = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        logradouro = new javax.swing.JTextField();
        municipio = new javax.swing.JTextField();
        dataNascimento = new javax.swing.JTextField();
        nomeMae = new javax.swing.JTextField();
        nomeResp = new javax.swing.JTextField();
        dataAlta = new javax.swing.JTextField();
        qDiarias = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        cep = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        telefone = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        idade = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        telResp = new javax.swing.JTextField();
        cidDiagnostico = new javax.swing.JTextField();
        procedimento = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        observacao = new javax.swing.JTextArea();
        botaoSalvar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jLabel1.setText("Nº Prontuário");

        jLabel2.setText("Data de Entrada");

        dataEntrada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dataEntradaActionPerformed(evt);
            }
        });
        dataEntrada.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                dataEntradaPropertyChange(evt);
            }
        });
        dataEntrada.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                dataEntradaKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                dataEntradaKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                dataEntradaKeyReleased(evt);
            }
        });

        jLabel3.setText("Nome do Paciente:");

        jLabel4.setText("Logradouro:");

        jLabel5.setText("Município:");

        jLabel6.setText("Data de Nascimento:");

        jLabel7.setText("Nome da Mãe:");

        jLabel8.setText("Pai ou Resp.:");

        jLabel9.setText("Data de Alta:");

        jLabel10.setText("Quantidade de Diárias:");
        jLabel10.setToolTipText("OBSERVAÇÕES: ");

        jLabel11.setText("Observação");

        dataNascimento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                dataNascimentoKeyPressed(evt);
            }
        });

        dataAlta.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                dataAltaKeyPressed(evt);
            }
        });

        jLabel12.setText("CEP: ");

        cep.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cepKeyPressed(evt);
            }
        });

        jLabel13.setText("Telefone:");

        telefone.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                telefoneKeyPressed(evt);
            }
        });

        jLabel14.setText("Idade:");

        idade.setEditable(false);

        jLabel16.setText("Telefone:");

        jLabel17.setText("CID-Diangóstico: ");

        telResp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                telRespKeyPressed(evt);
            }
        });

        jLabel18.setText("Procedimento:");

        jLabel15.setText("Ficha de Observação no Pronto Atendimento");

        observacao.setColumns(20);
        observacao.setRows(5);
        jScrollPane1.setViewportView(observacao);

        botaoSalvar.setText("Salvar");
        botaoSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSalvarActionPerformed(evt);
            }
        });

        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(municipio, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cep, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(dataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(20, 20, 20)
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(telefone, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel15)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jButton1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(botaoSalvar))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(logradouro))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(nProntuario, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(dataEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(nomePaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 353, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jLabel11)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(323, 323, 323)
                                        .addComponent(jLabel14)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(idade, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addComponent(jLabel10)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(qDiarias, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addComponent(jLabel9)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(dataAlta, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel18)
                                                    .addComponent(jLabel17))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(cidDiagnostico, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(procedimento, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel8)
                                                    .addComponent(jLabel7))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(nomeResp, javax.swing.GroupLayout.PREFERRED_SIZE, 403, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(nomeMae, javax.swing.GroupLayout.PREFERRED_SIZE, 403, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel16)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(telResp, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(7, 7, 7)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel15)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nProntuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(dataEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(nomePaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(logradouro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(municipio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(cep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(telefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(dataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(idade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(nomeMae, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(nomeResp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(telResp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(cidDiagnostico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dataAlta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(qDiarias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(procedimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoSalvar)
                    .addComponent(jButton1))
                .addGap(5, 5, 5))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void dataEntradaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataEntradaActionPerformed
                
    }//GEN-LAST:event_dataEntradaActionPerformed

    private void dataEntradaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dataEntradaKeyPressed
        if(evt.getKeyChar() != '\b'){
            dataEntrada.setText(Formatador.formataData(dataEntrada.getText()));
        }
    }//GEN-LAST:event_dataEntradaKeyPressed

    private void dataEntradaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dataEntradaKeyReleased
        
    }//GEN-LAST:event_dataEntradaKeyReleased

    private void dataEntradaPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dataEntradaPropertyChange

    }//GEN-LAST:event_dataEntradaPropertyChange

    private void dataEntradaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dataEntradaKeyTyped
        
        if(!(evt.getKeyChar() == '\b')){
            dataEntrada.setText(Formatador.formataData(dataEntrada.getText()));
        }
        
    }//GEN-LAST:event_dataEntradaKeyTyped

    private void botaoSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSalvarActionPerformed
        ficha.setCidDiag(cidDiagnostico.getText());
        ficha.setDataAlta(dataAlta.getText());
        ficha.setDataEntrada(dataEntrada.getText());
        ficha.setObs(observacao.getText());
        ficha.setProcedimento(procedimento.getText());
        ficha.setQtdDiarias(Integer.parseInt(qDiarias.getText()));
        FichaObservacaoPAJpaController oj = new FichaObservacaoPAJpaController();
        try {
            oj.edit(ficha);
        } catch (NonexistentEntityException ex) {
            JOptionPane.showMessageDialog(null, "Ficha não encontrada.");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro na comunicação com o Banco de Dados.");
        }
        setVisible(false);
    }//GEN-LAST:event_botaoSalvarActionPerformed

    private void dataNascimentoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dataNascimentoKeyPressed
       
        if(!(evt.getKeyChar() == '\b')){
            dataNascimento.setText(Formatador.formataData(dataNascimento.getText()));
        }
    }//GEN-LAST:event_dataNascimentoKeyPressed

    private void dataAltaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dataAltaKeyPressed
        if(!(evt.getKeyChar() == '\b')){
            dataAlta.setText(Formatador.formataData(dataAlta.getText()));
        }
    }//GEN-LAST:event_dataAltaKeyPressed

    private void cepKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cepKeyPressed
        if(!(evt.getKeyChar() == '\b')){
            cep.setText(Formatador.formataCEP(cep.getText()));
        }
    }//GEN-LAST:event_cepKeyPressed

    private void telefoneKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_telefoneKeyPressed
        if(!(evt.getKeyChar() == '\b')){
            telefone.setText(Formatador.formataTelefone(telefone.getText()));
        }
    }//GEN-LAST:event_telefoneKeyPressed

    private void telRespKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_telRespKeyPressed
        if(!(evt.getKeyChar() == '\b')){
            telResp.setText(Formatador.formataTelefone(telResp.getText()));
        }
    }//GEN-LAST:event_telRespKeyPressed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        setVisible(false);
        limpaCampos();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        limpaCampos();
    }//GEN-LAST:event_formWindowClosing
    
    public void limpaCampos(){
        dataEntrada.setText("");
        dataAlta.setText("");
        cidDiagnostico.setText("");
        qDiarias.setText("");
        procedimento.setText("");
        observacao.setText("");
        nProntuario.setText("");
        nomePaciente.setText("");
        logradouro.setText("");
        municipio.setText("");
        cep.setText("");
        telefone.setText("");
        dataNascimento.setText("");
        idade.setText("");
        nomeMae.setText("");
        nomeResp.setText("");
        telResp.setText("");
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaFichaObsPtAtd.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaFichaObsPtAtd.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaFichaObsPtAtd.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaFichaObsPtAtd.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                TelaFichaObsPtAtd.getInstance().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoSalvar;
    private javax.swing.JTextField cep;
    private javax.swing.JTextField cidDiagnostico;
    private javax.swing.JTextField dataAlta;
    private javax.swing.JTextField dataEntrada;
    private javax.swing.JTextField dataNascimento;
    private javax.swing.JTextField idade;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField logradouro;
    private javax.swing.JTextField municipio;
    private javax.swing.JTextField nProntuario;
    private javax.swing.JTextField nomeMae;
    private javax.swing.JTextField nomePaciente;
    private javax.swing.JTextField nomeResp;
    private javax.swing.JTextArea observacao;
    private javax.swing.JTextField procedimento;
    private javax.swing.JTextField qDiarias;
    private javax.swing.JTextField telResp;
    private javax.swing.JTextField telefone;
    // End of variables declaration//GEN-END:variables
    private FichaObservacaoPA ficha;
}
